package com.ymatou.query.trading.api.service;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymatou.query.seller.trading.api.parameter.GetBuyerOrderInfosResponseV2;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 获取买家订单列表
 */
public class GetBuyerOrderInfosV2Call extends YmatouBaseCall {
	private static String opurl = "api/App/GetBuyerOrderInfosV2";

	public GetBuyerOrderInfosV2Call() {
		super(EnvSetup.getSystemUrl("api_order_query"), opurl, "POST", "JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).getString("Code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public String getBCode() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("BCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("Msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public JSONObject getData() {
		JSONObject Data = null;
		try {
			Data = new JSONObject(getReturnData()).getJSONObject("Data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}
	
	public GetBuyerOrderInfosResponseV2 getBuyerOrderInfosResponseV2() {
		GetBuyerOrderInfosResponseV2 response = null;
		try {
			response = (GetBuyerOrderInfosResponseV2)FormatUtil.GSONToObject(new JSONObject(getReturnData()).getJSONObject("Data").toString(),GetBuyerOrderInfosResponseV2.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return response;
	}

	public JSONArray getOrderInfos() {
		JSONArray orderInfos = null;
		try {
			orderInfos = getData().getJSONArray("OrderInfos");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return orderInfos;
	}

	public Integer getLastOrderId() {
		Integer LastOrderId = null;
		try {
			LastOrderId = getData().getInt("LastOrderId");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return LastOrderId;
	}

}
